﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HT.Data.BussinessLogic;
using HT.Data.Objects;
using System.Data.SqlTypes;
namespace Hotel.Operations
{
    public partial class RoomStatus : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                LoadRoomType();
                GetBookingStatus();
            }
        }


        //public void LoadHotelList()
        //{
        //  ddlHotel.DataSource = HotelManger.GetInstance().GetAllHotel();
        //  ddlHotel.DataTextField = "HotelName";
        //  ddlHotel.DataValueField = "HotelId";

        //  ddlHotel.DataBind();

        //}

        public void LoadRoomType()
        {
            ddlRoomType.DataSource = HotelManger.GetInstance().GetAllRoomType(0, 0);
            ddlRoomType.DataValueField = "RoomTypeId";
            ddlRoomType.DataTextField = "RoomType";

            ddlRoomType.DataBind();
            ddlRoomType.Items.Insert(0, new ListItem("All", "0"));

        }

        public void GetBookingStatus()
        {
            int roomid = (ddlRoomType.SelectedValue == "") ? 0 : Convert.ToInt32(ddlRoomType.SelectedValue);
            GridStatus.DataSource = HotelManger.GetInstance().GetBookingStatus(0, roomid);
            GridStatus.DataBind();

        }

        protected void GridStatus_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (((HiddenField)e.Row.FindControl("hdn")).Value.Trim().ToLower() == "available")
                {
                    e.Row.FindControl("lnkCheckIn").Visible = true;
                    e.Row.Cells[1].BackColor = System.Drawing.ColorTranslator.FromHtml("#00FF00");

                    e.Row.FindControl("lnkView").Visible = false;
                    e.Row.FindControl("lnkStatus").Visible = false;
                }
                else if (((HiddenField)e.Row.FindControl("hdn")).Value.Trim().ToLower() == "occupied")
                {
                    e.Row.Cells[1].BackColor = System.Drawing.Color.Orange;
                    e.Row.FindControl("lnkStatus").Visible = false;
                    e.Row.FindControl("lnkCheckin").Visible = false;
                    e.Row.FindControl("lnkView").Visible = true;
                }
                else
                {
                    e.Row.Cells[1].BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFF00");
                    e.Row.FindControl("lnkStatus").Visible = true;
                    e.Row.FindControl("lnkCheckin").Visible = false;
                    e.Row.FindControl("lnkView").Visible = false;
                }
            }


        }

        protected void GridStatus_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Clear"))
            { 

                HotelManger.GetInstance().ClearRoomStatus(Convert.ToInt32(e.CommandArgument), 1);
                GetBookingStatus();

            }

        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            GetBookingStatus();

        }
    }
}